package com.xyz.frame.api.controller.shzhyun;

import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.shzhyun.pay.Service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping
@Slf4j
public class WechatController {

    @Autowired
    private WechatService wechatService;

    @RequestMapping(value = "/wechat/code2openId",method = RequestMethod.GET)
    public String code2openId(@RequestParam("code") String code
            ,@RequestParam(value = "appid",required = false) String appid){
        log.info("code:{},appid:{}",code,appid);
        return wechatService.code2OpenId(code,appid);
    }

    @RequestMapping(value = "/wechat/wx2688e56b7e5f8ead/callback",method = RequestMethod.POST)
    public String  wxeadcallback(HttpServletRequest servletRequest, HttpServletResponse response) {
        log.info("wxeadcallback request:{}",JSONObject.toJSONString(servletRequest));
        String res = "success";
        return res;
    }

    //小云优号
    @RequestMapping(
            value = "/wechat/wxa6cbd7b7e159d675/verifyToken",
            method = RequestMethod.GET,
            produces = "text/plain;charset=utf-8")
    public String verifyToken(@RequestParam(value = "signature", required = false) String signature,
                                @RequestParam(value = "timestamp", required = false) String timestamp,
                                @RequestParam(value = "nonce", required = false) String nonce,
                                @RequestParam(value = "echostr", required = false) String echostr) {
        log.info("verifyToken:{}",echostr);
        return echostr;
    }
    @RequestMapping(value = "/wechat/userinfo",method = RequestMethod.GET)
    public JSONObject userinfo(@RequestParam("code") String code
            ,@RequestParam(value = "appid",required = false) String appid){
        log.info("code:{},appid:{}",code,appid);
        return wechatService.userinfo(code,appid);
    }


}
